rpcd-mod-luci,luci-mod-network: suggest DUID%IAID values
authorDavid Härdeman <[email protected]>
Sun, 5 Oct 2025 09:52:36 +0000 (11:52 +0200)
committerPaul Donald <[email protected]>
Fri, 24 Oct 2025 18:23:34 +0000 (20:23 +0200)
Change the getDUIDHints RPC method to return "DUID%IAID" hints (if the IAID is
known, which it is with odhcpd). Use the complete hints in luci-mod-network.

Signed-off-by: David Härdeman <[email protected]>
libs/rpcd-mod-luci/src/luci.c
modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js

index 7cb56ae2afa56965dbc5d1728e616842dd1c4ddb..d030d43a74a092cdeda413119cc5a4b1d3a06bfa 100644 (file)
@@ -1830,29 +1830,27 @@ rpc_luci_get_duid_hints(struct ubus_context *ctx, struct ubus_object *obj,
                if (lease->af != AF_INET6 || lease->duid == NULL)
                        continue;
 
-               e = avl_find_element(&avl, lease->duid, e, avl);
+               size_t key_len = strlen(lease->duid) + 1 + (lease->iaid ? strlen(lease->iaid) + 1 : 0);
+               char key[key_len];
 
+               sprintf(key, "%s%s%s", lease->duid,
+                       lease->iaid ? "%" : "",
+                       lease->iaid ? lease->iaid : "");
+
+               e = avl_find_element(&avl, key, e, avl);
                if (e)
                        continue;
 
-               e = calloc_a(sizeof(*e), &p, strlen(lease->duid) + 1);
-
+               e = calloc_a(sizeof(*e), &p, key_len);
                if (!e)
                        continue;
 
-               o = blobmsg_open_table(&blob, lease->duid);
+               o = blobmsg_open_table(&blob, key);
 
-               inet_ntop(AF_INET6, &lease->addr[0].in6, s, sizeof(s));
-               blobmsg_add_string(&blob, "ip6addr", s);
+               blobmsg_add_string(&blob, "duid", lease->duid);
 
-               a = blobmsg_open_array(&blob, "ip6addrs");
-
-               for (n = 0; n < lease->n_addr; n++) {
-                       inet_ntop(AF_INET6, &lease->addr[n].in6, s, sizeof(s));
-                       blobmsg_add_string(&blob, NULL, s);
-               }
-
-               blobmsg_close_array(&blob, a);
+               if (lease->iaid)
+                       blobmsg_add_string(&blob, "iaid", lease->iaid);
 
                if (lease->hostname)
                        blobmsg_add_string(&blob, "hostname", lease->hostname);
@@ -1860,9 +1858,16 @@ rpc_luci_get_duid_hints(struct ubus_context *ctx, struct ubus_object *obj,
                if (!ea_empty(&lease->mac))
                        blobmsg_add_string(&blob, "macaddr", ea2str(&lease->mac));
 
+               a = blobmsg_open_array(&blob, "ip6addrs");
+               for (n = 0; n < lease->n_addr; n++) {
+                       inet_ntop(AF_INET6, &lease->addr[n].in6, s, sizeof(s));
+                       blobmsg_add_string(&blob, NULL, s);
+               }
+               blobmsg_close_array(&blob, a);
+
                blobmsg_close_table(&blob, o);
 
-               e->avl.key = strcpy(p, lease->duid);
+               e->avl.key = strcpy(p, key);
                avl_insert(&avl, &e->avl);
        }
 
index 14ae192cb0ecb79d78e7b89973a7fabfc843408e..89c17ff46cf8049704fba601bbac758609bb9be2 100644 (file)
@@ -874,8 +874,9 @@ return view.extend({
                        _('Syntax: <code>&lt;DUID-hex-str&gt;</code> <em>or</em> <code>&lt;DUID-hex-str&gt;%&lt;IAID-hex-str&gt;</code>'));
                so.rmempty = true;
                so.validate = validateDUIDIAID;
-               Object.keys(duids).forEach(function(duid) {
-                       so.value(duid, '%s (%s)'.format(duid, duids[duid].hostname || duids[duid].macaddr || duids[duid].ip6addr || '?'));
+               Object.keys(duids).forEach(function(duid_iaid) {
+                       var desc = duids[duid_iaid].hostname || duids[duid_iaid].macaddr || duids[duid_iaid].ip6addrs[0] || '?';
+                       so.value(duid_iaid, '%s (%s)'.format(duid_iaid, desc));
                });
 
                so = ss.option(form.Value, 'hostid',